import { defineConfig } from 'vite';
import vue from '@vitejs/plugin-vue';
import unocss from 'unocss/vite';
import path from 'node:path';
import markdown from 'unplugin-vue-markdown/vite';
import {
    presetAttributify,
    presetUno,
    presetIcons,
    presetWebFonts,
} from 'unocss';

function srcPath(url?: string) {
    return path.resolve(__dirname, 'src', url);
}
console.log(srcPath(''));

// https://vitejs.dev/config/
export default defineConfig({
    plugins: [
        unocss({
            presets: [
                presetUno(),
                presetAttributify(),
                presetIcons({
                    extraProperties: {
                        display: 'inline-block',
                        'vertical-align': 'middle',
                    },
                }),
                presetWebFonts({
                    provider: 'google',
                    fonts: {
                        dancing: 'Dancing Script',
                        ZC: 'ZCOOL XiaoWei',
                        pt: 'PT Serif',
                    },
                }),
            ],
        }),
        vue({
            include: [/\.vue$/, /\.md$/],
        }),
        markdown({
            include: ['src/**/*.md'],
            headEnabled: true,
        }),
    ],
    resolve: {
        alias: [
            { find: /@\//, replacement: `${srcPath('')}/` },
            { find: /@components/, replacement: srcPath('components') },
            { find: /@views/, replacement: srcPath('views') },
            { find: /@routes/, replacement: srcPath('routes') },
            { find: /@utils/, replacement: srcPath('utils') },
            { find: /@store/, replacement: srcPath('store') },
            { find: /@services/, replacement: srcPath('services') },
        ],
    },
});
